import React ,{Suspense} from 'react'
import {
    Navigate,
    Route,
    Routes,
    BrowserRouter,
    HashRouter
} from "react-router-dom"
import routes from "./RouterConfig"

function index({router}) {
    console.log(router);
    const renderRouter = (arr) =>{
        return arr.map((item,index)=>{
            return item.path? <Route key={index} path={item.path} element={<item.element></item.element>}>
                {
                    item.children&&renderRouter(item.children)
                }
            </Route>:<Route key={index} path={item.from} element={<Navigate to={item.to}/>}/>
        })
    }
    
    return (
        <Suspense fallback={<div>路由加载中...</div>}>
            {
                router === "H"? <HashRouter>
                    <Routes>
                        {
                            renderRouter(routes)
                        }
                    </Routes>
                </HashRouter>
            :<BrowserRouter>
                    <Routes>
                        {
                            renderRouter(routes)
                        }
                    </Routes>
                </BrowserRouter>
            }
           
        </Suspense>
    )
}

export default index
